#include "forwardlist.h"

void ShowData(DYMFListDataType *data)
{
    if(data == NULL) return;
    printf("Student Nunber:%lld, Sex:%s, Name:%s\n", data->ID, data->sex, data->name);
}

int Equal(DYMFListDataType *a, DYMFListDataType *b)
{
    if(a == NULL || b == NULL) return 0;
    if(a->ID == b->ID){ // 学号相等，即两个学生相等
        return 1;
    }
    return 0;
}
int main()
{
    DYMFListDataType tmpElem[4] ={
        {.ID = 16205140106, .sex = "M", .name = "Sun-yu"},
        {.ID = 16205140434, .sex = "F", .name = "Ding-yangmin"},
        {.ID = 16205140132, .sex = "M", .name = "Bu-yuanhao"},
        {.ID = 16205140131, .sex = "M", .name = "Zong-xun"}
    };

    DYMFList list = DYMFListCreate();
    for(int i = 0; i < 4; ++i)
    {
        DYMFListAdd(&list, tmpElem[0]);
    }
    for(int i = 0; i < 4; ++i)
    {
        DYMFListAdd(&list, tmpElem[0]);
    }

    DYMListForeach(&list, ShowData);    // 遍历链表所有元素，对所有元素执行 ShowData 函数，函数指针的初级应用
    printf("\n\n");

    DYMFListDelete(&list, tmpElem[0], Equal);   // 删除 第三个学生

    DYMListForeach(&list, ShowData);    // 遍历链表所有元素，对所有元素执行 ShowData 函数，函数指针的初级应用
    printf("\n\n");
    
    DYMFListDectory(&list); 
    return 0;
}